using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Poll : System.Web.UI.UserControl
{
	const string VS_POLL_ID = "pollId";
	public Guid? Id {
		get {
			return (Guid?)this.ViewState[VS_POLL_ID];
		}
		set {
			this.ViewState[VS_POLL_ID] = value;
			this.DataBind();
		}
	}

	protected Guid pollId {
		get {
			return this.Id.HasValue ? this.Id.Value : Guid.Empty;
		}
	}

	public bool Active {
		get {
			return (new PollService()).IsActive(this.pollId);
		}
	}

	public string Question {
		get {
			return (new PollService()).Question[this.pollId];
		}
		set {
			(new PollService()).Question[this.pollId] = value;
		}
	}
	
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!this.IsPostBack) {
			this.DataBind();
		}

    }
	protected void btnSubmitQuestion_Click(object sender, EventArgs e)
	{
		PollService _ps = new PollService();
		_ps.Clear(this.pollId);
		this.Question = (this.LoginView1.FindControl("tbQuestion") as TextBox).Text;
	}
	
	protected void btnYes_Click(object sender, EventArgs e)
	{
		(new PollService()).AddVote(this.pollId, true);
	}
	
	protected void btnNo_Click(object sender, EventArgs e)
	{
		(new PollService()).AddVote(this.pollId, false);
	}
	
	protected void upQuestion_Load(object sender, EventArgs e)
	{
		this.lQuestion.Text = this.Question;
		this.DataBind();
	}
	protected void upStat_Load(object sender, EventArgs e)
	{
		(sender as UpdatePanel).DataBind();
	}
	
	protected void btnStop_Click(object sender, EventArgs e)
	{
		this.Question = string.Empty;
	}
}
